package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Vip;
import com.ruoyi.system.service.IVipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * vip设置Controller
 * 
 * @author ruoyi
 * @date 2024-10-24
 */
@RestController
@RequestMapping("/vip")
public class VipController extends BaseController
{
    @Autowired
    private IVipService vipService;

    /**
     * 查询vip设置列表
     */
    @RequiresPermissions("vip:vip:list")
    @GetMapping("/list")
    public TableDataInfo list(Vip vip)
    {
        startPage();
        List<Vip> list = vipService.selectVipList(vip);
        return getDataTable(list);
    }

    /**
     * 导出vip设置列表
     */
    @RequiresPermissions("vip:vip:export")
    @Log(title = "vip设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Vip vip)
    {
        List<Vip> list = vipService.selectVipList(vip);
        ExcelUtil<Vip> util = new ExcelUtil<Vip>(Vip.class);
        util.exportExcel(response, list, "vip设置数据");
    }

    /**
     * 获取vip设置详细信息
     */
    @RequiresPermissions("vip:vip:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(vipService.selectVipById(id));
    }

    /**
     * 新增vip设置
     */
    @RequiresPermissions("vip:vip:add")
    @Log(title = "vip设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Vip vip)
    {
        return toAjax(vipService.insertVip(vip));
    }

    /**
     * 修改vip设置
     */
    @RequiresPermissions("vip:vip:edit")
    @Log(title = "vip设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Vip vip)
    {
        return toAjax(vipService.updateVip(vip));
    }

    /**
     * 删除vip设置
     */
    @RequiresPermissions("vip:vip:remove")
    @Log(title = "vip设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(vipService.deleteVipByIds(ids));
    }
}
